/* 获取小区经纬度 */
const puppeteer = require('puppeteer');
const ora = require('ora');
const FakeUseragent = require('fake-useragent');
const fs = require('fs');
const Paint = require('../tool/console.color');
const pageOption = {
  timeout: 0,
  waitUntil: 'domcontentloaded'
}
let url = 'http://api.map.baidu.com/lbsapi/getpoint/index.html';
async function getLongitudeAndLatitude(fileName) {
  let browser = await puppeteer.launch({
    headless: true
  });
  let [page] = await browser.pages();
  await page.setUserAgent(FakeUseragent());
  await page.goto(url, pageOption);
  // 点击切换城市
  await page.click('#curCityText');
  // 切换城市为郑州市
  await page.click('#selCity > tbody > tr:nth-child(11) > td:nth-child(2) > nobr:nth-child(1) > a');
  // 输入小区名称
  await page.type('#localvalue', '海逸名门');
  // 点击搜索
  await page.click('#localsearch');

  page.waitForSelector('#txtPanel > ul').then(async () => {
    //   // let data = await page.$$eval('#no_0 > p', elements => {
    //   //   if (elements.length) {
    //   //     return elements[0].childNodes[2].textContent.trim().match(/(?<=：).*/)[0].split(',');
    //   //   }
    //   //   return [];
    //   // })
    await page.click('#no0 > div');
    let data = await page.$$eval('#pointInput', els => {
      return els;
    })
    console.log(data);
    //   // console.log(data);
  }).catch(err => {
    console.log(err.message);
  })

  await browser.close();
}

getLongitudeAndLatitude();
